package com.hns.dev.linys.thread;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by admin on 2019/7/10.
 */
public class ThreadTest1 {

    public static Object lock = new Object();
    public static volatile int a = 0;
    public static int b = 0;
    public static ReentrantLock rl = new ReentrantLock();
    public static AtomicInteger ai = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i <= 10000 ; i++) {
            int finalI = i;
            Thread t = new Thread(() -> {
                // synchronized (lock) {a++;}
                rl.lock();
                b ++ ;
                rl.unlock();
                //ai.incrementAndGet();
                //System.out.println(finalI + "  Volatile=" + a);
                //System.out.println(finalI + "   AtomicInteger=" + ai.get());
                System.out.println(finalI + "  b=" + b);
            });
            t.start();
        }

    }


}
